package com.example.book.proxytest;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * like aspect
 *
 * 基于继承的方式实现代理
 * 不能代理static类 final类
 * 不能代理static方法，private方法
 */
public class CgLibProxy implements MethodInterceptor {
    @Override
    public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {

        System.out.println("PRE ...");
        Object res = methodProxy.invokeSuper(object, args);
        System.out.println("After ...");
        return res;
    }
}
